Обновить

Run i2pd in a Docker container on CentOS 7

Время на прочтение 3 min
Количество просмотров 9.5K

image On Habrahabr there is great article on i2pd. The only drawback of the project is that its authors provide packages only for Ubuntu and Debian, which is a certain inconvenience for CentOS users.


An owner of a home NAS on CentOS 7 like me can either build i2pd from source or use Docker, to install it over the Debian Jessie image.


So, the article is devoted to creating a container with i2pd in Docker under CentOS 7.


Installing Docker


Docker has its own repository with the latest versions. To connect it, let's create it in the directory /etc/yum.repos.d file docker.repo with the following content:


[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

Then install the package we need:


$ sudo yum install docker
$ sudo yum install docker-engine
$ sudo systemctl enable docker.service
$ sudo systemctl start docker

Now you can check the installation is correct:


$ sudo docker run --rm hello-world

And if everything is ok, then all we have to do is add the user who will dabble in containers to the docker group:


$ sudo usermod -aG docker cube

Creating an image


To do this we need to create a file Dockerfile with the following content:


FROM debian:jessie
MAINTAINER Cube <kyb.6.granei@yandex.ru>

# Эти порты нужны для того, чтобы наш контейнер был доступен
# как прокси и у нас был бы доступ на его консоль
EXPOSE 4444 4447 7070 9439

# Обновим образ
RUN apt-get update && apt-get upgrade

# Установим зависимости i2pd
RUN apt-get install -y  wget                \
            libboost-date-time1.55.0        \
            libboost-filesystem1.55.0       \
            libboost-program-options1.55.0  \
            libboost-system1.55.0           \
            libminiupnpc10

# Скачаем последнюю версию i2pd и установим пакет
RUN cd /tmp && wget https://github.com/PurpleI2P/i2pd/releases/download/2.9.0/i2pd_2.9.0-1jessie1_amd64.deb
RUN dpkg -i /tmp/i2pd_2.9.0-1jessie1_amd64.deb
RUN rm /tmp/i2pd_2.9.0-1jessie1_amd64.deb

# Делаем пользователя i2pd доступным - назначаем
# ему рабочий shell
RUN usermod -s /bin/bash i2pd 

# Копируем конфиг i2pd и файл с подписками 
# внутрь контейнера
COPY i2pd.conf /etc/i2pd/i2pd.conf
COPY subscriptions.txt /etc/i2pd/subscriptions.txt 

# Определяем точку входа нашего контейнера.
# Эта команда запустится при его запуске
ENTRYPOINT exec su - i2pd -c "/usr/sbin/i2pd --conf ~/i2pd.conf"

There should be two files next to the Dockerfile.


  • i2pd.conf (the config is working, but if you wish, you can fix it to your liking):

log = stdout

daemon = false
service = false

## Port to listen for connections
## By default i2pd picks random port. You MUST pick a random number too,
## don't just uncomment this
port = 9439 

## Enable communication through ipv4
ipv4 = true

## Enable communication through ipv6
ipv6 = true

## Bandwidth configuration
## L limit bandwidth to 32Kbs/sec, O - to 256Kbs/sec, P - to 2048Kbs/sec,
## X - unlimited
## Default is X for floodfill, L for regular node
bandwidth = O

## Router will be floodfill
# floodfill = true

[http]
## Uncomment and set to 'false' to disable Web Console
enabled = true
## Address and port service will listen on
address = 0.0.0.0
port = 7070

[httpproxy]
## Uncomment and set to 'false' to disable HTTP Proxy
enabled = true
## Address and port service will listen on
address = 0.0.0.0
port = 4444
## Optional keys file for proxy local destination
# keys = http-proxy-keys.dat

[socksproxy]
## Uncomment and set to 'false' to disable SOCKS Proxy
enabled = true
## Address and port service will listen on
address = 0.0.0.0
port = 4447

  • subscriptions.txt is a file with subscriptions

http://inr.i2p/export/alive-hosts.txt
http://stats.i2p/cgi-bin/newhosts.txt
http://i2p-projekt.i2p/hosts.txt
http://i2host.i2p/cgi-bin/i2hostetag
http://no.i2p/export/alive-hosts.txt
http://rus.i2p/hosts.txt
http://udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p/hosts.txt

Now let's run the command to create our image. Docker will automatically download and install the required layers:


$ docker build -t i2pd .

Launching the container


$ docker run --name=i2pd  -td -p 7070:7070 -p 4444:4444 -p 4447:4447 -p 9439:9439 i2pd

key -p indicates which ports to open to the outside, and -td starts a process in the background, while it continues to write logs to stdout, which is a standard practice when using containers and allows you to conveniently view its output with the command:


$ docker logs -t i2pd

After launch, the console of our i2pd is available via port 7070, and http- and socks-proxy by port 4444 And 4447 respectively.


For the lazy


For those who don’t want to create a container themselves, I made a ready-made one on Docker hub. It is installed with one command:


$ docker pull hexaedron/i2pd

It starts in exactly the same way as described above.


Conclusion


I'll finish the article link to github — there is the Dockefile itself, a couple of scripts for starting and stopping and configs. I hope the information is useful to someone. I will be glad to constructive criticism.

Tags:
Hubs:
Всего голосов 14: ↑11 и ↓3 +8
Комментарии 7
+7

Comments 7

I would like to take this opportunity to announce that I was released today Release 2.10.0 i2pd, tested, in particular, when working in Docker.
Thank you! Updated the script on Github and the image on Docker hub.
A CentOS 7 home NAS owner like me is left with either building i2pd from source or using Docker to install it on top of the Debian Jessie image.

Your NAS is good…
… I'll just leave it This here.
Focus on i2pd-2.10.0-1.fc24.2.src.rpm
I think you know how to use rpmbuild.

Thanks, I was considering this option. The point is that, judging by documentation:
Centos 7 has CMake 2.8.11 in the official repositories that too old to build i2pd, CMake &gt;=2.8.12 is required.

assembling i2pd from a src package will entail at least an assembly from src and cmake. This is all relatively labor-intensive and slow. The container is collected and updated if necessary for a minute, and does not create garbage in the system. This is not a development environment, but a simple NAS.

Yes, yes... they, the developers, know exactly what is in the package database)

The point is that according to the documentation:

Don't trust anyone, everyone lies.
So, in C6 and C7 there is CMake 3.x, and it is in EPEL. He appeared there somewhere in March 2016.
Small manipulations solve almost all issues:


%if 0%{?rhel}  == 7
BuildRequires:  cmake3
%else
BuildRequires:  cmake
%endif

You can pick up ready-made packages for C7 here, https://copr.fedorainfracloud.org/coprs/vorona/i2pd/, something like this:


curl -s https://copr.fedorainfracloud.org/coprs/vorona/i2pd/repo/epel-7/vorona-i2pd-epel-7.repo -o /etc/yum.repos.d/i2pd-epel-7.repo
yum install i2pd-systemd -y
Live and learn!
Thank you!